import { ID } from "/@/api/models";
import { SelectItem } from "/@/types/antd";

export function firstCharToUpper(str?: string) {
  if (!str || typeof str != "string") return str;
  return str.replace(str[0], str[0].toUpperCase());
}

export function coverObj(originObj: any, newObj: any, cb?: (key: string, value: any) => any) {
  for (const i in originObj) {
    const newValue = newObj[i];
    if (newValue !== undefined) {
      if (cb) {
        const result = cb(i, newValue);
        if (result !== undefined) {
          originObj[i] = result;
          continue;
        }
      }
      originObj[i] = newValue;
    }
  }
}
export const DATE_FORMAT_STR = "YYYY-MM-DD";
export const DATETIME_FORMAT_STR = "YYYY-MM-DD HH:mm:ss";

export function getLabelByValue(value: ID, data: SelectItem[]) {
  const item = data.find((el) => el.value === value);
  return item ? item.label : null;
}
